<?php
/**
 * @author li ming
 * @date 2021-10-14
 */
namespace Modules\Order\Http\Controllers\Api;

use Modules\Order\Services\Api\OrderServices;
use Modules\Order\Services\Api\OrderSubmitServices;
use Modules\Order\Services\Api\OrderListServices;
use Modules\Order\Services\Api\ShareOrderServices;
use Modules\Order\Services\Api\OrderPayDataServices;

class OrderController extends ApiBaseController
{
    private $services;
    private $submitServices;
    private $orderListServices;
    private $shareOrderServices;
    private $orderPayDataServices;

    /**
     * @param OrderServices $orderServices
     */
    public function __construct(
        OrderServices $orderServices,
        OrderSubmitServices $orderSubmitServices,
        OrderListServices $orderListServices,
        ShareOrderServices $shareOrderServices,
        OrderPayDataServices $orderPayDataServices
        )
    {
        $this->services = $orderServices;
        $this->submitServices = $orderSubmitServices;
        $this->orderListServices = $orderListServices;
        $this->shareOrderServices = $shareOrderServices;
        $this->orderPayDataServices = $orderPayDataServices;
    }

    /**
     * 确认订单
     * @return mixed  placeOrder
     */
    public function confirmOrder()
    {
        try {
            $result = $this->services->confirmOrder();
            return $this->success($result);
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 提交订单
     * @return
     */
    public function submitOrder()
    {
        try {
            $result = $this->submitServices->submit();
            return $this->success($result);
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 订单列表
     * @return
     */
    public function list()
    {
        try {
            $result = $this->orderListServices->list();
            return $this->success($result);
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 订单取消
     * @return
     */
    public function revoke()
    {
        try {
            $result = $this->orderListServices->revoke();
            return $this->success('', $result);
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 确认收货
     * @return
     */
    public function confirm()
    {
        try {
            $result = $this->orderListServices->confirm();
            return $this->success($result);
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 订单详情
     * @return
     */
    public function detail()
    {
        try {
            $result = $this->orderListServices->detail();
            return $this->success($result);
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 订单物流
     */
    public function expressDetail()
    {
        try {
            $result = $this->orderListServices->getExpressDetail();
            return $this->success($result);
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 分销订单
     * @return
     */
    public function shareOrder()
    {
        try {
            $result = $this->shareOrderServices->list();
            return $this->success($result);
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 订单支付数据
     * @return
     */
    public function payData(){
        try {
            $result = $this->orderPayDataServices->search();
            return $this->success($result);
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 订单支付回调
     */
    public function notify()
    {
        try {
            $result = $this->orderPayDataServices->notify();
            return $this->success($result);
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }
    
}